package com.autologistics.dao;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.autologistics.model.Goods;
import com.autologistics.model.User;

public class UserInfoDaoImpl implements UserInfoDao{
	private HibernateTemplate hibTemplate;

	public HibernateTemplate getHibTemplate() {
		return hibTemplate;
	}

	public void setHibTemplate(HibernateTemplate hibTemplate) {
		this.hibTemplate = hibTemplate;
	}
	public List<User> listAll(){
		String hql="from User ";
		List<User> list = hibTemplate.find(hql);
		if (!list.isEmpty()){
			return list;
		}else
		{
			return null;
		}
	}
	public User getById(int id){
		String hql = "from User where id = ?";
		List<User> list = hibTemplate.find(hql,id);
		if (!list.isEmpty()){
			return list.get(0);
		}else
		{
			return null;
		}
	}
	public User getByAccountPwd(String ac,String pwd){
		String hql= "from User where account=? and pwd=?";
		List<User> list = hibTemplate.find(hql,new Object[]{ac,pwd});
		if (!list.isEmpty()){
			return list.get(0);
		}else{
			return null;
		}
	}
	
	//周毅增加的
	//update object user.
	public void updateUser(User user){
		hibTemplate.update(user);
	}
}
